镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support for Compound Conditions In WHILE Loops #396

Open

Description

@x87

Introduce WHILE OR and WHILE AND variations of WHILE loop with support for multiple conditions.

Current state

https://docs.sannybuilder.com/language/control-flow/loops#while..end

Proposed Syntax

WHILE OR
  <cond 1>
  <cond 2>
  ...
  <cond N>
DO
  <loop body> // execute while at least one condition is true
END
WHILE AND
  <cond 1>
  <cond 2>
  ...
  <cond N>
DO
  <loop body> // execute while all conditions are true
END

DO keyword is needed to separate a condition list from the loop body.

Workround

WHILE TRUE
   IF OR/AND
    <conds>
   THEN
     <loop body>
   ELSE
      BREAK
   END
END

Activity

  1. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    Alternative syntax (inspired by gta3script syntax):

    // single condition
    WHILE <COND>
    ...
    END
    
    // compound condition (AND/OR)
    WHILE <COND1>
        OR <COND2>
        OR <COND3>
    ...
    END
    
    // single condition
    REPEAT
    ...
    UNTIL <COND>
    
    // compound condition (AND/OR)
    REPEAT
    ...
    UNTIL <COND1>
        OR <COND2>
        OR <COND3>
    

    Can be expanded to IF (note that THEN becomes redundant):

    IF <COND>
        OR <COND2>
        OR <COND3>
    [THEN]
    ...
    END
    
  2. MiranDMC commented on May 2, 2026

    @MiranDMC
    if and
    foo()
    foo()
    foo()
    

    So where conditions ends and body starts? Seems like it makes it only more convoluted instead clearer

  3. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    if and
    foo()
    foo()
    foo()
    then

    end

  4. MiranDMC commented on May 2, 2026

    @MiranDMC

    There is no then in previous example

    // compound condition (AND/OR)
    WHILE <COND1>
        OR <COND2>
        OR <COND3>
    ...
    END
    
  5. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    AND / OR itself are indicators

  6. MiranDMC commented on May 2, 2026

    @MiranDMC

    IF 24
    These values are not even an enum.

    I would just stick to high level constructs. There is already too much alternative ways to do same things in SB.
    People are spending time on naming labels and inventing their own command names following opcode number instead writing the script itself.

  7. MiranDMC commented on May 2, 2026

    @MiranDMC

    Didn't we earlier discussed the

    while
    then
    end
    

    ?
    Do is probably more fitting natural language, but it is introducing an new keyword?
    If there is do I naturally start thinking about do-while-end instead of repeat-until

  8. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    if and
    IF 24

    this syntax was mentioned nowhere in the proposal, read carefully

  9. MiranDMC commented on May 2, 2026

    @MiranDMC
    // compound condition (AND/OR)
    WHILE <COND1>
         OR <COND2>
         OR <COND3>
    ...
    END
    

    Oh ok there is OR as prefix for every condition line.
    Does it support mixed logical operations? If not it will be frequently asked question why this does not work.

  10. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor
    // compound condition (AND/OR)
    WHILE <COND1>
         OR <COND2>
         OR <COND3>
    ...
    END
    

    Oh ok there is OR as prefix for every condition line. Does it support mixed logical operations? If not it will be frequently asked question why this does not work.

    No, it does not support mixed operators. Either all AND, or all OR. That's how it works in original scripts too.

    Image
  11. MiranDMC commented on May 2, 2026

    @MiranDMC

    So there is no benefit in that approach.
    You are trying to fix one of the anomalies: the conditions in loops are not behaving same way as in if.
    Now you inventing ways to make them work differently anyway.
    Keep it simple and consistent. Nobody have head to remember all the quirks.

    Same with THEN and DO keywords

  12. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    Which part of the proposal is inconsistent? While/Repeat/If all use either single condition, or multiple conditions joined with AND or OR.

  13. MiranDMC commented on May 2, 2026

    @MiranDMC

    #396 (comment)
    Proposing syntax inspired by gta3script. I would like to see SB inspired one instead...

    Take code:

    if or
        foo == 1
        foo == 2
    then
        ...
    end
    

    Replace if with while, done. No need for overthinking now or later when typing in scripts.

  14. x87 commented on May 2, 2026

    @x87
    CollaboratorAuthor

    But it does not work with REPEAT..UNTIL, that's the issue

  15. MiranDMC commented on May 2, 2026

    @MiranDMC

    repeat-until-end easy to deduce as no new keywords are introduced or new concept of prefixing each condition expression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions