- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
While loop
- While loop is used to repeat an action until a condition is true.- While loop written by while keyword.
- Value of x is repeated until a condition is true, after that condition is false then the value repetition stop.
- Value of x is repeated till 9 because the condition is true till 9 and after 9 the condition will be false. (In the below code)
- In the below code, 10 is excluded
Output:
While loop break statement:
- Break statement is used to stop the loop where we add the break condition.- Break statement written by break keyword.
- In the below code, 5 is excluded in the output because we add the break condition at 5 in the if statement before print.
- Syntax: if x == Value :
break
- In the below code, 5 is included in the output because we print the loop before the break condition at 5 in the if statement.
While loop continue statement:
- Continue statement is used to exclude the specific value and continue the loop with the next value.- Continue statement written by continue keyword.
- In the below code, 6 is excluded in the output because we add the continue condition at 6 in the if statement before print.
- Syntax: if x == Value:
continue
- Get link
- X
- Other Apps
Comments
Post a Comment