is there a simple one-line way to write an if statement? Topic is solved
is there a simple one-line way to write an if statement?
Ask a simple question weakly, is there a simple one-line way to write an if statement? For example: if a=1 then gosub xxx
Last edited by cgx5871 on 27 Jan 2022, 00:39, edited 1 time in total.
- flyingDman
- Posts: 2791
- Joined: 29 Sep 2013, 19:01
Re: is there a simple one-line way to write an if statement?
Code: Select all
(a=1) && a := 2
Code: Select all
a := a=1 ? 2 : "" ; if a is = 1 then a = 2 else a is an empty string
14.3 & 1.3.7
Re: is there a simple one-line way to write an if statement?
I think you may mean ? instead of &&
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Re: is there a simple one-line way to write an if statement?
That was not what I meantflyingDman wrote: ↑26 Jan 2022, 23:58or with "else" conditionCode: Select all
(a=1) && a := 2
Code: Select all
a := a=1 ? 2 : "" ; if a is = 1 then a = 2 else a is an empty string
like this:
if a=1 then gosub xxx
- flyingDman
- Posts: 2791
- Joined: 29 Sep 2013, 19:01
- flyingDman
- Posts: 2791
- Joined: 29 Sep 2013, 19:01
Re: is there a simple one-line way to write an if statement? Topic is solved
You can try:
Code: Select all
gosub % a = 1 ? "label1" : "label2"
14.3 & 1.3.7
-
- Posts: 482
- Joined: 03 Dec 2018, 20:02
Re: is there a simple one-line way to write an if statement?
Alternatively, there's a two line way to write this:
Code: Select all
if (a=1)
gosub xxx
Re: is there a simple one-line way to write an if statement?
That was not what I meant
like this:
if a=1 then gosub xxx
Code: Select all
!a::
Random, a, 0, 1
(a=1) ? goSub(1) : goSub(0)
SoundBeep
Return
goSub(x) {
MsgBox % x
}
Re: is there a simple one-line way to write an if statement?
Re: is there a simple one-line way to write an if statement?
@flyingDman, @boiler, wow that's nice. I even didn't know about this trick, thanks!
Also we can use (a = 1) || a := 3 as alternatives to:
If a != 1
a := 3
or
(a != 1) && a := 3
It is strange that (a = 1) ? a := 2 also works although ternary operator is built to include false-branch too.
Also we can use (a = 1) || a := 3 as alternatives to:
If a != 1
a := 3
or
(a != 1) && a := 3
It is strange that (a = 1) ? a := 2 also works although ternary operator is built to include false-branch too.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.