Jump to content

Recommended Posts

Hello,

 

I have created this code:

 

if (w > maxWidth || h > textHeight) {
if (y < x) {
[y, y]
} else {
[x, x]
}
} else {
[value[0], value[1]]
}

 

It is a piece, but it gives to understand what I want to optimize without the rest.

 

How to modify this code to work with: Switch Statement instead If/Else mode?

 

This is a expression of After Effects.

 

Thanks.

Link to post
Share on other sites

It would, but if you're doing a switch on a boolean it usually makes more sense to use an if/else structure. If your goal is optimization, you don't see big performance increases by using a switch over an if/else structure.

Link to post
Share on other sites

It would, but if you're doing a switch on a boolean it usually makes more sense to use an if/else structure. If your goal is optimization, you don't see big performance increases by using a switch over an if/else structure.

I can do this:

 

function getValue() {
switch (true) {
case yB < xA:
return [yB, yB];
default:
return [xA, xA];
}
}


E = getValue();


if (w > maxWidth || h > textHeight){
x = E[0]; y = E[1];
}


[x, y];
Edited by tiscavalcanti
Link to post
Share on other sites

I can do this:

Yes, you can, but since we're talking about optimizing and efficiency, what does this do for you:

 

switch (true) {
  case yB < xA:
    return [yB, yB];
  default:
    return [xA, xA];
}
that is better than this:

 

if (yB < xA) {
  return [yB, yB];
}
else {
  return [xA, xA];
}
or this:

 

return (yB < xA) ? [yB, yB] : [xA, xA];
Link to post
Share on other sites

Yes, you can, but since we're talking about optimizing and efficiency, what does this do for you:

 

switch (true) {
  case yB < xA:
    return [yB, yB];
  default:
    return [xA, xA];
}
that is better than this:

 

if (yB < xA) {
  return [yB, yB];
}
else {
  return [xA, xA];
}
or this:

 

return (yB < xA) ? [yB, yB] : [xA, xA];
This way is interesting:
return (yB <xA)? [yB, yB]: [xA, xA];
Could you explain a little more how it works.
The use of interrogation, is something new to me.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...