DEV Community

Lalit Kumar
Lalit Kumar

Posted on

Can you have a while loop inside if condition?

The question we will discuss in this article is “can you have a while loop inside if condition?”
Yes!!! We can have a while loop inside a if condition. The if statement only is condition if that happens then do this otherwise follow the other statement and the while loop is the repetition statement. We can use while loop inside an if statement as a conditional statement.

If statement

Programs use selection statements to choose among other paths of actions. For example: If a student's grade is greater than or equal to 60 then print “passed”. The if statement is a single-entry/exit statement.

While loop

A repetition/loop statement specifies that a program should repeat an action while some condition remains true.

Read more

Top comments (2)

Collapse
 
snjjay profile image
James

nice one

Collapse
 
whataluckyguy profile image
Lalit Kumar

Thanks Snjjay