increment

Increment on “__toString”

人盡茶涼 提交于 2019-12-04 03:55:35
I am not sure what the title should be, but the code should explain it better: class Group { private $number = 20; public function __toString() { return "$this->number"; } } $number = new Group(); echo $number, PHP_EOL; echo ++ $number, PHP_EOL; echo PHP_EOL; $number = "20"; echo $number, PHP_EOL; echo ++ $number, PHP_EOL; echo PHP_EOL; $number = 20; echo $number, PHP_EOL; echo ++ $number, PHP_EOL; Output: 20 20 <--- Expected 21 20 21 20 21 Any idea why I got 20 instead of 21 ? Even then the code below works: $i = null ; echo ++$i ; // output 1 I know Group is an object that implements _

PHP Increment by Half

浪子不回头ぞ 提交于 2019-12-04 03:11:22
I have a quick question, which is probably easy to answer. I've goolged around, but not sure if I am searching correctly or what. Anyway, using PHP, how can I increment by halves? For example, I know I can use the following loop: <?php for ($i=1; $i<21; $i++) { print($i); } And it will print 1 - 20. But, how can I get it to output something like the following: 1 1.5 2 2.5 etc... Sorry for my ignorance on this, I'm just not sure how to go about it. Thanks! Change $i++ to $i += 0.5 . Also, to print each number on its own line you need to use \n (or <br> if you're outputting HTML to a browser).

How to save excel file with incrementing number?

不羁岁月 提交于 2019-12-03 23:05:17
问题 I am looking for VBA to add to my macro that will increment the file name if the file name already exists. Current Code: Dim filepath As String Dim filename As String Dim filepatharch As String Dim filedate As String Dim filelist As String 'Grab FROM list number Sheets("TD File").Select Range("G4").Select filelist = ActiveCell.Value 'Grab today's date filedate = Format(Now, "MMDD01.") --------------Currently where the '01' comes from (see below) 'Set where to save and the file naming

Android studio value increment in Firebase

♀尐吖头ヾ 提交于 2019-12-03 22:36:10
问题 Can anyone teach me how to update my Firebase value when I click on my Android Studio App? There is no need to retrieve and display the data. Just an incremental of value in my Firebase. For example, the Firebase counter value is 0 now, how I can increase the counter value in Firebase when I click on a button? I have tried using the code below, but it is not working. import com.firebase.client.Firebase; public class Voting extends AppCompatActivity { private Button msendData; int counter;

How to increment a number by 2 in a PHP For Loop

跟風遠走 提交于 2019-12-03 22:13:07
The following is a simplified version of my code: <?php for($n=1; $n<=8; $n++): ?> <p><?php echo $n; ?></p> <p><?php echo $n; ?></p> <?php endfor; ?> I want the loop to run 8 times and I want the number in the first paragraph to increment by 1 with each loop, e.g. 1, 2, 3, 4, 5, 6, 7, 8 (this is obviously simple) However, I want the number in the second paragraph to increment by 2 with each loop, e.g... 1, 3, 5, 7, 9, 11, 13, 15 I can't figure out how to make the number in the second paragraph increment by 2 with each loop. If I change it to $n++ then it increments by 2, but it then makes the

Pointer incrementing in C++

心不动则不痛 提交于 2019-12-03 15:20:41
What does this mean: that a pointer increment points to the address of the next base type of the pointer? For example: p1++; // p1 is a pointer to an int Does this statement mean that the address pointed to by p1 should change to the address of the next int or it should just be incremented by 2 (assuming an int is 2 bytes), in which case the particular address may not contain an int ? I mean, if p1 is, say, 0x442012, will p1++ be 0x442014 (which may be part of the address of a double) or will it point to the next int which is in an address like 0x44201F? Thanks Pointer arithmetic doesn’t care

C# - increment number and keep zeros in front

拥有回忆 提交于 2019-12-03 10:53:39
I need to make a 40 digit counter variable. It should begin as 0000000000000000000000000000000000000001 and increment to 0000000000000000000000000000000000000002 When I use the int class, it cuts off all the zeros. Problem is I need to increment the number and then convert it to a string, with the correct number of leading zeros. The total size should be 40 digits. So if I hit 50 for example, it should look like this: 0000000000000000000000000000000000000050 How can I do that and retain the zeros? Anthony Pegram Use the integer and format or pad the result when you convert to a string. Such as

How to make a pointer increment by 1 byte, not 1 unit

旧巷老猫 提交于 2019-12-03 10:42:20
I have a structure tcp_option_t , which is N bytes. If I have a pointer tcp_option_t* opt , and I want it to be incremented by 1, I can't use opt++ or ++opt as this will increment by sizeof(tcp_option_t) , which is N . I want to move this pointer by 1 byte only. My current solution is opt = (tcp_option_t *)((char*)opt+1); but it is a bit troublesome. Are there any better ways? I'd suggest you to create a pointer of char and use it to transverse your struct. char *ptr = (char*) opt; ++ptr; // will increment by one byte when you need to restore your struct again, from ptr, just do the usual cast

Python dictionary increment

给你一囗甜甜゛ 提交于 2019-12-03 06:38:15
问题 In Python it's annoying to have to check whether a key is in the dictionary first before incrementing it: if key in my_dict: my_dict[key] += num else: my_dict[key] = num Is there a shorter substitute for the four lines above? 回答1: An alternative is: my_dict[key] = my_dict.get(key, 0) + num 回答2: You have quite a few options. I like using Counter: >>> from collections import Counter >>> d = Counter() >>> d[12] += 3 >>> d Counter({12: 3}) Or defaultdict: >>> from collections import defaultdict >

Increment a string with letters?

拜拜、爱过 提交于 2019-12-03 06:22:22
I need to increment a string from.. let's say aaa to zzz and write every incrementation in the console (is incrementation even a word?). It would go something like this: aaa aab aac ... aaz aba abb abc ... abz aca acb And so on. So far I have incremented a single letter by doing this: String.prototype.replaceAt = function(index, character) { return this.substr(0, index) + character + this.substr(index+character.length); } string = "aaa"; string = string.replaceAt(2, String.fromCharCode(string.charCodeAt(2) + 1)); //string == "aab" However, I am lost when it comes to the final letter being z