Discuss Scratch
- Discussion Forums
- » Suggestions
- » ?-Operator [inline if-then-else]
- TheCreatorOfUnTV
-
Scratcher
1000+ posts
?-Operator [inline if-then-else]
Basically, an in-line if-then-else construct. Handy, certainly, but nothing that can't be done fairly well with other blocks. For instance, on your last example, you could do the same thing with this:Read this Vif <(pick random (1) to (2)) = [1]> then
set [value v] to [1]
else
set [value v] to [-1]
end
Perhaps even more easily understood than the in-line version.
Yes because code can be made more concise (usually) while still being readable (in a lot of cases)Is there a clear benefit to fitting in Boolean inputs? In what situation would it be needed? /genIsn’t that justIt is basically this, but this is easier since you do not have to create a result variable or anything, and can fit in reporter inputs (also, this has been used in other places too):if <> then
else
endif <bool::grey> then
set [result v] to (first result::grey)
else
set [result v] to (second result::grey)
end
Last edited by TheCreatorOfUnTV (July 8, 2024 23:03:27)
- fhqhwgads9sb
-
Scratcher
20 posts
?-Operator [inline if-then-else]
Basically, an in-line if-then-else construct. Handy, certainly, but nothing that can't be done fairly well with other blocks. For instance, on your last example, you could do the same thing with this:What? Do you want big chungus in your code? No, what are you even thinking!?if <(pick random (1) to (2)) = [1]> then
set [value v] to [1]
else
set [value v] to [-1]
end
Perhaps even more easily understood than the in-line version.
- bubgamer07
-
Scratcher
100+ posts
?-Operator [inline if-then-else]
do not the blockspamif <[Block] = [E Block]> then
The If <> then, else block looks like a E block.
else
say [this looks like double c block.]
end
- Catzcute4
-
Scratcher
500+ posts
?-Operator [inline if-then-else]
Actually very useful for select-a-or-b operations, like max. Would you rather:
if <(a)>(b)> thenor
return (a) :: custom
else
return (b) :: custom
end
if <(a)>(b)> then (a) else (b) :: operators reporter? Especially when having to do multiple of this at once, this is better. Either that or custom reporters (seriously, custom reporters really should be added, but that’s offtopic). Plus, this exists in js. Sure, for in loops exist, and they’re complicated, but the if <> then () else () literally explains itself right there.
Last edited by Catzcute4 (Feb. 6, 2025 00:30:34)
- Crow_Boy08
-
Scratcher
1000+ posts
?-Operator [inline if-then-else]
It's only 5 blocks. It's not like the work around is 30 blocks or so.Basically, an in-line if-then-else construct. Handy, certainly, but nothing that can't be done fairly well with other blocks. For instance, on your last example, you could do the same thing with this:What? Do you want big chungus in your code? No, what are you even thinking!?if <(pick random (1) to (2)) = [1]> then
set [value v] to [1]
else
set [value v] to [-1]
end
Perhaps even more easily understood than the in-line version.
- hypercode96
-
Scratcher
100+ posts
?-Operator [inline if-then-else]
Duplikate, I suggested the same a while ago:you just called dupe on the very thing the original topic was
http://scratch.mit.edu/discuss/topic/33995/?page=1#post-286812
And support of course
if that wasn't enough it was your own topic






- Dorianek12345678
-
Scratcher
4 posts
?-Operator [inline if-then-else]
if <> [] else []::operators reporter
is
define if <condition> (text1) else (text2)
if <condition> then
set [value v] to (text1)
else
set [value v] to (text2)
end
- tagrim123
-
Scratcher
500+ posts
?-Operator [inline if-then-else]
So wait, what's the problem withso you can set it to values depending on if something returns true, and want to do something with the value at that exact moment.when green flag clickedYou didn't say anything about how the boolean could be useful, you just said how it works and what it does. Unless there are some pros or cons listed, I think I'll stick to -1
ask [Are you cool?] and wait
if <> then
say [Good!] for (2) secs
else
say [What!?] for (2) secs
end
- Discussion Forums
- » Suggestions
-
» ?-Operator [inline if-then-else]










