<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Loops
During the course of solving client requirements, comes across situations where group of some data needs to be processed against a defined set of instructions. 
Loops help in resolving situations where a piece of code needs to be executed against a set of data repetitedly or till certain condition is met or un-met. Or, you use to process a large quantity of data, such as lines of a file or records of a database that must be processed by the same code block.
Python provides two constructs to help in these situations.
for
while
Lets start with the for loops.
For
It is one of the most often used construct in Python. It can accept not only accept static sequences, but also sequences generated by iterators (Structures which allow iterations, i.e. sequentially access to collection of elements). It runs the code block against known iterations of dataset.
The syntax for for is as follows
Step1:  In the above example, "Manish Gupta" is a sequence of characters and for loop traverse that sequence of characters. Also you will note that we are ending the print statement with space instead of new line using the option end=. 
Similarly in the below example we are going to use the range function to generate the sequence of numbers starting from 30 and ending with 5 with difference of 5. 
The range() function
The function range(m, n, p), is very useful in loops, as it returns a list of integers starting at m through smaller than n in steps of length p, which can be used as the order for the loop.
We can also define the start, stop and step size as range(start,stop,step size). step size defaults to 1 if not provided.
We can generate a sequence of numbers using range() function. range(10) will generate numbers from 0 to 9 (10 numbers).
This function does not store all the values in memory, it would be inefficient. So it remembers the start, stop, step size and generates the next number on the go.
To force this function to output all the items, we can use the function list().
Step2:  Nested loops
We can also have nested for loops as shown in the below example
Step3:  NOTE
Step4:  for loop with a list
Step5:  we can also have conditions where multiple values are returned every iteration.
Step6:  for loop with dictionary.
Traversing the values.
Step7:  Traversing the keys
Step8:  Uses of forloops
Reading & processing a log file which contains logs one line at a time. 
While
Executes a block of code in response to a condition.
Syntax
Step9:  NOTE
Step10:  NOTE
Step11:  Break
The break statement is used to exit a for or a while loop. The purpose of this statement is to end the execution of the loop (for or while) immediately and the program control goes to the statement after the last statement of the loop. If there is an optional else statement in while or for loop it skips the optional clause also
Step12:  Continue Statement
The continue statement is used in a while or for loop to take the control to the top of the loop without executing the rest statements inside the loop. Here is a simple example.
Step13:  The else in for
Step14:  Usecases for else
A common use case for the else clause in loops is to implement search loops; say you’re performing a search for an item that meets a particular condition, and need to perform additional processing or raise an error if no acceptable value is found
<ASSISTANT_TASK:>
Python Code:
for x in "Manish":
    print(x, end=" ")
Explanation: Loops
During the course of solving client requirements, comes across situations where group of some data needs to be processed against a defined set of instructions. 
Loops help in resolving situations where a piece of code needs to be executed against a set of data repetitedly or till certain condition is met or un-met. Or, you use to process a large quantity of data, such as lines of a file or records of a database that must be processed by the same code block.
Python provides two constructs to help in these situations.
for
while
Lets start with the for loops.
For
It is one of the most often used construct in Python. It can accept not only accept static sequences, but also sequences generated by iterators (Structures which allow iterations, i.e. sequentially access to collection of elements). It runs the code block against known iterations of dataset.
The syntax for for is as follows:
Syntax:
for &lt;reference&gt; in &lt;sequence&gt;:
    &lt;code block&gt;
    continue
    break
else:
    &lt;code block&gt;
During the execution of a for loop, the reference points to an element in the sequence. At each iteration, the reference is updated, in order for the for code block to process the corresponding element.
The clause break stops the loop and continue passes it to the next iteration. The code inside the else is executed at the end of the loop, except if the loop has been interrupted by break.
Example:
End of explanation
# Output: range(0, 10)
print(range(10))
# Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(list(range(10)))
# Output: [2, 3, 4, 5, 6, 7]
print(list(range(2, 8)))
# Output: [2, 5, 8, 11, 14, 17]
print(list(range(2, 20, 3)))
print(list(range(20, 2, -3)))
print(dir(range(10)))
# Sum 0 to 99
s = 0
for x in range(30, 1, -5):
    print(x)
    s = s + x
print("sum of 30 to 1 with steps -5 is", s)
# Sum 0 to 99
s = 0
for x in range(30, 1, -5):
    print(x)
    s += x
print("sum of 30 to 1 with steps -5 is", s)
Explanation: In the above example, "Manish Gupta" is a sequence of characters and for loop traverse that sequence of characters. Also you will note that we are ending the print statement with space instead of new line using the option end=. 
Similarly in the below example we are going to use the range function to generate the sequence of numbers starting from 30 and ending with 5 with difference of 5. 
The range() function
The function range(m, n, p), is very useful in loops, as it returns a list of integers starting at m through smaller than n in steps of length p, which can be used as the order for the loop.
We can also define the start, stop and step size as range(start,stop,step size). step size defaults to 1 if not provided.
We can generate a sequence of numbers using range() function. range(10) will generate numbers from 0 to 9 (10 numbers).
This function does not store all the values in memory, it would be inefficient. So it remembers the start, stop, step size and generates the next number on the go.
To force this function to output all the items, we can use the function list().
End of explanation
for x in range(1, 6):
    for y in range(1, x+1):
        print(x, y)
Explanation: Nested loops
We can also have nested for loops as shown in the below example
End of explanation
for x in range(1, 6):
    for x in range(1, x+1):
        print(x, x)
Explanation: NOTE: Please avoid below case
End of explanation
cols = ["Red", "Green", "Yellow", "White"]
for color in cols:
    print(color)
cols = ["Red", "Green", "Yellow", "White"]
for color in cols:
    print(color)
else:
    print(" ~~~~ Done ~~~~")
Explanation: for loop with a list
End of explanation
# Advance code, to be used after learning slicing. Please use instead the other code
# for x in "Manish Gupta"[::-1]:
#     print(x, end=" ")
reverse_text = ""
for char in "Manish Gupta":
    reverse_text = char + reverse_text
print(reverse_text)
x_test = [[1,2],[3,4],[5,6]]
for x in x_test:
    print(x)
    a = x[0]
    b = x[1]
    print (a, b)
x_test = [[1,2],[3,4],[5,6], [7,8,9]]
for x in x_test:
    print(x)
x_test = [[1,2],[3,4],[5,6], [7,8]]
for x, y in x_test:
    print(x, y)
x_test = [[1,2],[3,4],[5,6], [7,8,9]]
for x in x_test:
    print(x)
    a = x[0]
    b = x[1]
    print (a, b)
Explanation: we can also have conditions where multiple values are returned every iteration.
End of explanation
color = {"c1": "Red", "c2": "Green", "c3": "Orange"}
for value in color.values():
    print(value)
Explanation: for loop with dictionary.
Traversing the values.
End of explanation
color = {"c1": "Red", "c2": "Green", "c3": "Orange"}  
for col in color:
    print(col, color[col])
color = {"c1": "Red", "c2": "Green", "c3": "Orange"}  
for value in color.values():
    if(value=="Green"): 
        break
    print(value)
else:
    print("Done")
color = {"c1": "Red", "c2": "Green", "c3": "Orange"}  
for value in color.values():
    if(value=="Green"): 
        continue
    print(value)
else:
    print("Done")
Explanation: Traversing the keys
End of explanation
# Sum 0 to 99
s = 0
x = 1
while x < 100:
    s = s + x
    x = x + 1
else:
    print("!!! Hurry Hurry !!!")
    print(x)
print ("Sum of 0 to 99", s)
# Sum 0 to 99
s = 0
x = 1
while x < 100:
    s += x
    x += 1
else:
    print("!!! Hurry Hurry !!!")
    print(x)
print ("Sum of 0 to 99", s)
Explanation: Uses of forloops
Reading & processing a log file which contains logs one line at a time. 
While
Executes a block of code in response to a condition.
Syntax:
while &lt;condition&gt;:
    &lt;code block&gt;
    continue/break/pass
else:
    &lt;code block&gt;
The code block inside the while loop is repeated while the loop condition is evaluated as true.
Example:
End of explanation
while x < 0:
    print("Hello")
else:
    print("Sorry")
# while x > 0:
#     print("Hello")
# else:
#     print("Sorry")
Explanation: NOTE: Bad Code Below
End of explanation
s = 0
x = 100
while x < 100:
    s = s + x
    x = x + 1
else:
    print("x is already equal or greater than 100")
print(s)
x = 1;  
s = 0  
while (x < 10):  
    s = s + x  
    x = x + 1  
    if (x == 5):
        break  
else:  
     print('The sum of first 9 integers : ',s)          
print('The sum of', x, 'numbers is :',s)   
while 10 != int(input('Enter a passkeyid: ')):
    print("Wrong Passkey"),
while int(input('Enter a passkeyid: ')) != 10:
    print("Wrong Passkey"),
else:
    print("!!! Welcome to the world of Magic !!!")
Explanation: NOTE: Please try to avoid code similar to above commented code
NOTE: The while loop is appropriate when there is no way to determine how many iterations will occur and there is a sequence to follow.
End of explanation
num_sum = 0  
count = 0  
for x in range(1, 9):  
    print(x)
    num_sum = num_sum + x  
    count = count + 1   
    if count == 5:  
        break 
print("Sum of first ",count,"integers is : ", num_sum)  
Explanation: Break
The break statement is used to exit a for or a while loop. The purpose of this statement is to end the execution of the loop (for or while) immediately and the program control goes to the statement after the last statement of the loop. If there is an optional else statement in while or for loop it skips the optional clause also
End of explanation
for x in range(8):  
    if (x == 3 or x==6):
        print("\tSkipping:", x)
        continue  
        print("This should never print")
    else:
        print(x) 
Explanation: Continue Statement
The continue statement is used in a while or for loop to take the control to the top of the loop without executing the rest statements inside the loop. Here is a simple example.
End of explanation
for x in [1, 10, 4]:
    if x == 10:
        continue
    print("Hello", x)
else:
    print("processing completed without issues.")
print("-" * 20)
for x in [1, 10, 4]:
    if x == 10:
        break
    print("Hello", x)
else:
    print("processing completed without issues.")
Explanation: The else in for
End of explanation
def meets_condition(x):
    return x==20
data = [10, 20, 33, 42, 44]
for x in data:
    if meets_condition(x):
        break
else:
    print("No one met the condition")
print("lets end it")
def meets_condition(x):
    return x==21
data = [10, 20, 33, 42, 44]
for x in data:
    if meets_condition(x):
        break
else:
    print("No one met the condition")
print("lets end it")
print(list(range(2, 4)))
print(4%2)
n-> 2:
    x <- []
n -> 3:
    x -> 2
    3%2 
    Prime number
n -> 4
    x -> [2, 3]
        4%2
n -> 5:
    x -> [2, 3, 4]
        
for n in [2, 3, 4, 5, 6, 7, 8, 9]:
    for x in range(2, n):
        if n % x == 0:
            print(n, 'equals', x, '*', n/x)
            break
    else:
        # loop fell through without finding a factor
        print(n, 'is a prime number')
Explanation: Usecases for else
A common use case for the else clause in loops is to implement search loops; say you’re performing a search for an item that meets a particular condition, and need to perform additional processing or raise an error if no acceptable value is found:
End of explanation
<END_TASK>