How to make or simulate a do while like in program

  • I am trying of create a game when I need a DO While, can this is simulate?

  • Do While is just an extra syntax depending on language. You need to just use while with a condtion

    While

    count > 0

    --- count - 1

    so yes you can.

    Manual scirra.com/manual/124/system-conditions

    it's in there somewhere :D

  • ok, thank you!

  • the do while is a special case of a while function in a programming language, where the predicate is evaluated at the end of the code block it executes.

    so you usually have

    Always do the first iteration, and then if the predicate is true reiterate.

    So to simulate something like

    set i to 0
    do {
     append i to text
     i = i + 1
    } while (i < 10)

    you would do

    + system: every tick
        -> system: set i to 0
        -> text: append i to text
        -> system: add 1 to i
    + system: while 
    + system: i < 10
        -> text: append i to text
        -> system: add 1 to i

    as you see a do while is merely a syntaxic sugar to avoid repeating some of the code you write.

  • I am trying to make something like this

    int x=10;

    int random=0;

    do{

    random =((int) Math.random() * 100);

    if(random==4){

    x=10/random;

    }

    }while(x==2.5);

    (this is java code)

    I know this can seem useless, but I want know if to make this is possible in construct 2

  • Yann you can also write it like this to eliminate repetitive events:

    + system: every tick
        -> system: set i to 0
    + system: while 
        -> text: append i to text
        -> system: add 1 to i
        + [inverted] system: i < 10
            ->system: stop loop

    shimo you could do it like this:

    + system: every tick
        -> system: set x to 10
        -> system: set random_var to 0
    + system: while 
        -> system: set random_var to int(random(100))
        + system: random_var==4
            -> system: set x to 10/random_var
        + [inverted] system: x == 2.5
            ->system: stop loop
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    indeed thanks (:

  • Thank you so much! Yann and RojoHound

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)