الثابتة ‎ranges.until()‎ في لغة Kotlin

من موسوعة حسوب
< Kotlin‏ | ranges
مراجعة 18:15، 2 يوليو 2018 بواسطة محمد-بغات (نقاش | مساهمات) (أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الثابتة <code>‎ranges.until()‎</code> في لغة Kotlin}}</noinclude> تعيد الدالة ‎<code>until()‎</code> مجالا...')
(فرق) → مراجعة أقدم | المراجعة الحالية (فرق) | مراجعة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث

تعيد الدالة ‎until()‎ مجالا متدرّجًا (progression) تنازليًا من القيمة التي استُدعيت عبرها وحتى القيمة الممرّرة. ينبغي أن تكون القيمة الممررة أصغر من القيمة التي استُدعيت عبرها الدالة، وإلّا ستعيد الدالة مجالا متدرجا فارغًا.

البنية العامة

infix fun Int.downTo(to: Byte): IntProgression 
infix fun Long.downTo(to: Byte): LongProgression 
infix fun Byte.downTo(to: Byte): IntProgression 
infix fun Short.downTo(to: Byte): IntProgression 
infix fun Char.downTo(to: Char): CharProgression 
infix fun Int.downTo(to: Int): IntProgression 
infix fun Long.downTo(to: Int): LongProgression 
infix fun Byte.downTo(to: Int): IntProgression 
infix fun Short.downTo(to: Int): IntProgression
infix fun Int.downTo(to: Long): LongProgression 
infix fun Long.downTo(to: Long): LongProgression 
infix fun Byte.downTo(to: Long): LongProgression 
infix fun Short.downTo(to: Long): LongProgression 
infix fun Int.downTo(to: Short): IntProgression 
infix fun Long.downTo(to: Short): LongProgression 
infix fun Byte.downTo(to: Short): IntProgression 
infix fun Short.downTo(to: Short): IntProgression

القيمة المُعادة

مجال متدرّج (progression) تنازلي.

مثال

استخدام الدالة until()‎

في الشيفرة التالية نعرّف عددين x و y، ثم نعرّف مجال متدرّج p عبر استدعاء الدالةuntil()‎ عبر x ونمرر إليها الوسيط y ، ثم نستخدم p في حلقة for:

fun main(args: Array<String>) {    
    val x = 9 
    val y = 4
    val p = x.downTo(y) 
    
    for (a in p) print(a) // 987654
}

أنظر أيضًا

  • الثابتةcategory‎ : تساوي القيمة القصوى لبديل وحدة اليونيكود (Unicode surrogate code unit).

مصادر