Problem in while loop command

i am not getting my while loop syntax

Can you please explain further.
The syntax should be:-

while the boolean cond.:
statements in the loop
That’s it, make sure that your condition is a boolean expression and it is followed by a colon.

ans2
In 32nd line. While loop should start from the same space or tab distance of n=0 (31st line)

In python, indentation has a meaning.
The error lies in line 32 where you have accidentally added an indentation to the while statement. Note that the statements within the while loop body should be intended at the next level as you have done, but the loop header itself belongs to the main function and hence must not be indented.

The correct syntax is:-

n=0
while(n<10):
    print(n)
    n=n+1

i have doubt in html part where we have to do all the html coding. as shown in this photo from where do i found this folder section.

Hi @aasthasheral when you save your code then it ask for a location or folder , you can save it by creating a folder so for next time you can use the code easily.

so we are using replit html na ?

Hi @aasthasheral Yes.

a ‘while’ loop allows you to repeatedly execute a block of code as long as a certain condition is true. Here’s the basic syntax for a ‘while’ loop:

while condition:
# code to be executed

  1. The condition is evaluated. If it’s True, the code inside the loop is executed. If it’s False, the loop is exited, and the program continues with the code that follows the loop.
  2. After executing the code inside the loop, the program goes back to the beginning of the while statement and re-evaluates the condition.
  3. If the condition is still True, the loop is executed again. This process continues until the condition becomes False.

for example :

count = 0

while count < 5:
print(“Count:”, count)
count += 1

print(“Loop completed”)

Write the syntax properly and try again once.
Hope ,this will solve your problem.

The while loop should have the same indentation as the previous line (line 31).
contri

I’d be happy to help you with the syntax for a while loop. In Python, the while loop allows you to repeatedly execute a block of code as long as a certain condition is true. Here’s the basic syntax:

while condition:
    # Code block to be executed
    # while the condition is true

The condition is an expression that evaluates to either True or False. As long as the condition remains True, the code block inside the loop will be executed repeatedly. Once the condition becomes False, the loop will exit, and the program will continue with the next line of code after the loop.

Here’s an example that demonstrates the usage of a while loop:

count = 0
while count < 5:
    print("Count:", count)
    count += 1

In this example, the while loop will continue executing the code block as long as count is less than 5. Inside the loop, it prints the value of count and then increments it by 1. The loop will repeat this process until count becomes 5, at which point the condition becomes False, and the loop will exit.

Make sure to pay attention to the condition and ensure that it eventually becomes False to avoid infinite loops. It’s important to include a mechanism within the loop to change the variables or conditions being checked so that the loop can eventually terminate.

I hope this helps! If you have any specific questions or if there’s anything else I can assist you with, please let me know.

In 32nd line. While loop should start from the same space or tab distance of n=0 (31st line)

@aasthasheral here in the while loop section there is an intendation problem. The loop should be in the same intedaton as the line above it.

image

In python, indentation has a meaning.
The error lies in line 32 where you have accidentally added an indentation to the while statement. Note that the statements within the while loop body should be intended at the next level as you have done, but the loop header itself belongs to the main function and hence must not be indented.

The correct syntax is:-

n=0
while(n<10):
    print(n)
    n=n+1

Any Statement that are inside the loop should have proper indentation,
example:
count = 0
while(count<5):
---->print(count)
---->count=count+1
print(“Loop Completed”)

Proper indentation is crucial in Python as it determines the structure and hierarchy of the code.
There is no problem in your while loop syntax . The error occurred because while loop is written with an indentation. And indentation is not needed as while loop is already inside the main function.

As we know that the syntax for while loop in python is:

while Boolean-condition:

Statements

So we can see that after the colon there should be a indentation present to identify the block of the while loop and there should not be any space before while keyword. In your program there is an space before the while keyword, it should be in the same indent as the line 31 n=0, that’s why your code is giving error unexpected indent.
Hope it helps.

hello @aasthasheral,
the issue with this code is in (line 32), where there’s no proper indentation being followed.
the while loop header shouldn’t be indented as it belongs to the main function. it should have the same indentation as the previous (line 31).

image

If the conditional expression gives a boolean value True, the while loop statements are executed .
Example : i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)