PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] How to switch between multiple Values in a cycle?

 October 17, 2022     count, cycle, integer, qml, variables     No comments   

Issue

I want to switch between multiple values in a cycled kind of way. For example my variable "Counter" is initialised with 1 and by mouseclick i want it to switch to 2. Another mouseclick will change it to 3 and the next click will repeat the cycle by 1.

How do i do it by using QML?

Thank you in advance!


Solution

onClicked{    
switch(counter) {
  case 1:
    counter=2
    break;
  case 2:
    counter=3
    break;
  case 3:
    counter=1
    break;
  default:
    console.log("counter out of rotation)
}
}

A switch-case statement should do the trick inside an "onClicked" handler of a button. You can also do it in many different other ways. Like incrementing counter by +1 each time you press the button and add a if statement that sets counter to 1 again when it reaches the value of 4.



Answered By - Xic
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing