Discuss Scratch

TheCreatorOfUnTV
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Paddle2See wrote:

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:

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.
Read this V

ajskateboarder wrote:

starlightsparker wrote:

medians wrote:

starlightsparker wrote:

Isn’t that just
if <> then 

else

end
It 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 <bool::grey> then
set [result v] to (first result::grey)
else
set [result v] to (second result::grey)
end
Is there a clear benefit to fitting in Boolean inputs? In what situation would it be needed? /gen
Yes because code can be made more concise (usually) while still being readable (in a lot of cases)

Last edited by TheCreatorOfUnTV (July 8, 2024 23:03:27)

fhqhwgads9sb
Scratcher
20 posts

?-Operator [inline if-then-else]

Paddle2See wrote:

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:

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.
What? Do you want big chungus in your code? No, what are you even thinking!?
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

Bringing this topic up.
bubgamer07
Scratcher
100+ posts

?-Operator [inline if-then-else]

leidymateo wrote:

if <[Block] = [E Block]> then 

The If <> then, else block looks like a E block.

else
say [this looks like double c block.]
end
do not the blockspam
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)> then 
return (a) :: custom
else
return (b) :: custom
end
or
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]

fhqhwgads9sb wrote:

Paddle2See wrote:

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:

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.
What? Do you want big chungus in your code? No, what are you even thinking!?
It's only 5 blocks. It's not like the work around is 30 blocks or so.
hypercode96
Scratcher
100+ posts

?-Operator [inline if-then-else]

PH-zero wrote:

Duplikate, I suggested the same a while ago:
http://scratch.mit.edu/discuss/topic/33995/?page=1#post-286812

And support of course
you just called dupe on the very thing the original topic was

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]

20btheilmanngohr wrote:

So wait, what's the problem with
when green flag clicked
ask [Are you cool?] and wait
if <> then
say [Good!] for (2) secs
else
say [What!?] for (2) secs
end
You 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
so you can set it to values depending on if something returns true, and want to do something with the value at that exact moment.
medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

medians
Scratcher
1000+ posts

?-Operator [inline if-then-else]

medians wrote:

tagrim123
Scratcher
500+ posts

?-Operator [inline if-then-else]

Snap! has this

Powered by DjangoBB