+ 1
Write repeat-until equivalent using while loop.
repeat-until execute the statements inside the loop till the condition is false. whereas while loop executes the statements inside loop till the condition is true. I need repeat-until equivalent of while loop with appropriate example. Thanks, SagaTheGreatđŻ
2 Réponses
+ 5
pass the condition with a negation
while ( !(condition))
this will execute the block until the condition is false.
example:
i= 0
while( !(i==5))  // run until i isn't equal to 5
{ cout<<i;
  i++;
}
output: 01234
+ 1
In python
myVar = 0
while True :
    myVar += 1
    if myVar == 5 :
           print 'myVar is '+str(myVar)
           break
    else:
           print 'printing "else" block'
in c++
#include <iostream>
using namespace std;
int main()
{
    int myVar = 0;
while(true)  
{ 
    if(myVar ==5){
    cout<<myVar;
    break;
}
else{
    cout<<"printing else block \n";
}
  myVar++;
}
}



