How to stop the code execution when using an if statement in AdonisJS? - adonis.js

I'm trying to stop the code if a certain condition is met.
if(condition) {
stop the code
}
This code never gets executed if condition was met.
I tried break;
I tried return;
I tried anything I found on the web.
Adonis always executes the next line of code. Any ideas?
Thanks.

Related

am trying to write a simple if statement but my IDLE only reads the first part of my code and not the if statement if statement

am trying to write a simple if statement but my IDLE only reads the first part of my code and not the if statement
age=int(input("Enter your age"))
if age>=18:
print("Congratulations you are eligible to vote")
Everything is fine, just fix the indentation.
age=int(input("Enter your age"))
if age>=18:
print("Congratulations you are eligible to vote")

QT does not respond using a while loop

I've searched around without luck to get the answer to this question.
I'm doing a UART communication, I want to read data continuously if I have the button pressed or in the "down" position. The problem is that I'm using a while loop to do it. When I try to stop reading and release the button, the program freezes and does not respond. Any help will be appreciated it. Part of the code is below.
void MainWindow::on_pushButton_3_toggled(bool checked)
{
while(checked)
{
QByteArray datas = Serial_port.readAll();
ui->textEdit->setText((QString)datas);
qDebug()<<"Im here";
msleep(100);
qDebug()<<datas;
qDebug()<<checked;
}
qDebug()<<checked;
}
You're blocking the event loop, therefore, Qt can't process events. You could try calling QApplication::processEvents() during your loop, and that should make the UI responsive again.
why you need a loop to exec this code? are you using function connect() to made your click event correct? whem you click u start your loop and you don't have a end of this loop, you don't need this loop, you readall from serial port and put it in QBytearray when it finally readall the function read the next line and next at until end of function!
but if your need to continue using the loop try to made a checkbox in your ui, to get true or false and put a if in in loop to stop your loop
if(ui->cb->isChecked())
checked = true;
else
checked=false;

do-while doesn't quit on first 'q'

So I'm working on a simple little text-based game in D to gain some experience working with the language. Here is a do-while loop that I'm currently struggling with:
do{
writeln("a. Advance 1 year\tc. Advance 10 years\tq. Quit");
writeln("b. Advance 5 years\td. Modify faction");
input = chomp(stdin.readln());
switch(input){
...
default:
break;
}
writeln(input[0]);
}while(input[0] != 'q');
Now the problem I'm running into is that when I hit q and enter the loop doesn't exit. It just keeps going. But then after the first time q is input, another q will terminate the loop. The writeln is in there as a sanity check, and it prints out the characters I type in exactly as typed. I feel like I'm going crazy, but it's probably just a simple type-o or something you guys will spot instantly. Nothing in the switch statement modifies 'input'.
EDIT: Okay some people have been asking to see all of the code. Here it is: http://pastebin.com/A7qM5nGW
When I said nothing in the switch modified input, it was to hide the fact I hadn't written anything in the switch yet. I've been trying to get the quit part to work right before adding the more complicated stuff. Also, here's a sample file for what I run it on: http://pastebin.com/4c2f4Z5N
Okay my friend found it. It has nothing to do with the while loop itself. I briefly forgot that args[0] is the name of the program. So it's actually running through the parent loop once with nothing, then actually quitting, and then running through the appropriate loop. It was fixed by making the parent loop like so...
foreach(filename; args[1..$]){
...
do{
...
while(input[0] != 'q');
}
as opposed to:
foreach(filename; args){
etc...

Break and rerun while loop c++ Windows

I'm a rookie programmer, so please be polite.
Well i'm trying to write a simple Terminal Backgammon game, just for fun, but i have a problem.
The entire game runs in a while loop which keeps re running as long as nobody moved all their bricks to the end of the board.
A simple integer controls whatever it is black or white who plays.
I wrote a function to check for any possible moves, cause i want to program to skip the turn in case absolutely no moves can be made.
Well, i want this function to run and in case it returns false(No possible moves) then i want the rest of the code to skip and change the turn to the next player. For example if the dice combination gives no possible moves for black, then i want the program to skip black and go to white.
So i sort of want to break the rest of the while loop, but keep it running.
It's a little complicated for me to explain the issue, but i hope you guys understand.
Thanks alot
- Martin
It sounds like you want to use continue:
while (someCondition)
{
doSomething();
if (someOtherCondition)
continue;
doSomethingElse();
}
In this example, if someOtherCondition is true, the continue statement will cause the program to jump back to the top of the loop rather than continuing to execute the following statements. If someOtherCondition is false, doSomethingElse() will get run as normal.
I think this is roughly what you want to know.
Hope it helps.
while( keepRunning )
{
bool noPossibleMoves = checkForPossibleMoves();
setup for each loop iteration
Do things here that are always necessary.
if( noPossibleMoves )
{
continue; // This will go to the top of the while loop
}
wait for user input etc...
...
...
}

Is it possible to skip over an abitrary amount of a loop during debug?? Visual Studio

I am trying to find an error in my code. The problem is the error occurs in a loop. But the loop iterates about 500 times. Instead of clicking through the loop. Is it possible to skip over a certain amount of the loop ??
VS allows you to set a condition on a breakpoint in terms of variables that are in scope. So, in your case, you can test against the loop counter.
Here is a crude answer:
if ((iter % 10) == 0) {
int stop = 1;
}
Then place a break-point at "int stop = 1;". Perhaps, there is a better way in VS but this is what I do from time-to-time.
You can assign new values to variables during debug session. Step through the loop statements as many times as you like, then set your loop counter (or whatever other vars maintain loop condition) to terminate the loop.
Just put the breakpoint in the loop like indicated below >>. Use F5 to get to the condition that causes failure so you can loop through the individual pass. How to know where to break is up to you.
for (int i = 0; i < LOOPMAX; i++) {
>>some_proc(i);
some_other_proc(i);
some_third_proc(i);
}
By pressing F5 it'll continue running till it gets to the next breakpoint (the next pass through the code). Sure you'll have to hit it 500 times, but that beats some thousands of times. Combine this with #Troubador code above.
PS: This answer IS really simple, but some people don't know they can do this.